'use strict';
const {
  Model, INTEGER
} = require('sequelize');
module.exports = (sequelize, DataTypes) => {
  // class driver extends Model {
  //   /**
  //    * Helper method for defining associations.
  //    * This method is not a part of Sequelize lifecycle.
  //    * The `models/index` file will call this method automatically.
  //    */
  //   static associate(models) {
  //     // define association here
  //   }
  // };
  const truck=sequelize.define('truck',{
    TruckID:{
      allowNull: false,
      primaryKey: true,
      type: DataTypes.INTEGER,
      autoIncrement:true
    },
    TruckLic:{
      type: DataTypes.STRING,
      unique:true
    },
    FleetID:{
      type:DataTypes.INTEGER,
      allowNull:false
    },
    TruckInfo:{
      type:DataTypes.STRING,
    },
    TruckType:{
      type:DataTypes.STRING,
    },
    TruckReg:{
      type:DataTypes.STRING
    },  
    Status:{
      type:DataTypes.INTEGER
    }
  },{
    timestamps:false
});
//updated by xulin 20220217
truck.associate = function (models) {
  truck.belongsTo (models.receipt, {
    foreignKey: 'TruckLic',
    targetKey: 'TruckLic',
    as:'receipt',
    constraints:false
      })
     truck.belongsTo (models.Fleet, {
        foreignKey: 'FleetID',
        sourceKey: 'FleetID',
        // targetKey: 'FleetID',
        as:'fleets',
        constraints:false
       })
      }
      
  return truck;
};